module.exports = class shoppingService {
  static async getShoppingData(uid, page) {
    const shopping = require("../model/shopping")();
    return await shopping
      .where({ uid })
      .order("cid", "DESC")
      .limit((page - 1) * 10, page * 10)
      .select();
  }

  static async getSum(uid) {
    const shopping = require("../model/shopping")();
    return await shopping.where({ uid }).count();
  }

  static async addShopping(data) {
    const shopping = require("../model/shopping")();
    return await shopping.insert(data);
  }

  // 删除
  static async batchDeteleShopping(data) {
    const shopping = require("../model/shopping")();

    const cids = data.map((item) => item.cid);
    for (let i = 0; i < data.length; i++) {
      await shopping
        .where({
          cid: cids[i],
        })
        .del();
    }
    return true;
  }
};
